package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.Vehicleplan;
import com.intelligentcar.springboot.mapper.LogMapper;
import com.intelligentcar.springboot.mapper.VehicleplanMapper;
import com.intelligentcar.springboot.service.VehicleplanServer;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class VehicleplanServerImpl implements VehicleplanServer {
    @Autowired
    private LogMapper logMapper;
    @Autowired
    private VehicleplanMapper vehicleplanMapper;

    //车辆排班
    @Override
    public int vehicleSchedulinga(HttpServletRequest req, Vehicleplan vehicleplan) {
        req.getSession().setAttribute("userName", "王五");
        String time = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String logUser = req.getSession().getAttribute("userName").toString();
        logMapper.addLog(time, "排班", logUser, "车辆排班");
        return vehicleplanMapper.vehicleSchedulinga(vehicleplan);
    }

    //根据车牌号查看车辆排班表中的数据
    @Override
    public List<Vehicleplan> selectvehicleSchedulinga(Vehicleplan vehicleplan, RowBounds rowBounds) {
        return vehicleplanMapper.selectvehicleSchedulinga(vehicleplan, rowBounds);
    }

    //根据线路查看车辆排班表中的数据
    @Override
    public List<Vehicleplan> selectvehicleSchedulingax(Vehicleplan vehicleplan, RowBounds rowBounds) {
        return vehicleplanMapper.selectvehicleSchedulingax(vehicleplan, rowBounds);
    }

    //根据车牌号查看车辆排班表中有几条数据
    @Override
    public int countvehicleSchedulinga(Vehicleplan vehicleplan) {
        return vehicleplanMapper.countvehicleSchedulinga(vehicleplan);
    }

    @Override
    public int countvehicleSchedulingax(Vehicleplan vehicleplan) {
        return vehicleplanMapper.countvehicleSchedulingax(vehicleplan);
    }


    //查询车辆排版表中所有数据
    @Override
    public List<Vehicleplan> selectVehicleplan(RowBounds rowBounds) {
        return vehicleplanMapper.selectVehicleplan(rowBounds);
    }

    //根据车牌号查看车辆信息表的数据
    @Override
    public List<Vehicleplan> lookvehicleplan(Vehicleplan vehicleplan) {
        return vehicleplanMapper.lookvehicleplan(vehicleplan);
    }
    //查询有几条数据
    @Override
    public int count() {
        return vehicleplanMapper.count();
    }

}
